package org.uoss.webapp.framework.struts2.action;

import org.uoss.applications.framework.exception.BIZException;
import org.uoss.webapp.framework.exception.WebPageException;
import org.uoss.webapp.framework.http.HttpUtil;
import org.uoss.webapp.framework.struts2.object.UserSessionObject;

import com.uoss.applications.modules.permission.facade.PermissionFacade;
import com.uoss.applications.modules.permission.model.UserPermission;



public class LogonAction extends GenericAction<UserSessionObject> {
	private static final long serialVersionUID = -3645379462627730078L;
	private static final String LOGOUT = "logout";
	private PermissionFacade permissionFacade;

	@Override
	public UserSessionObject getModel() {
		return null;
	}
	
	public String forward2Logon(){
		return LogonAction.LOGOUT;
	}
	
	public String logon() throws WebPageException{
		//try {
			//String agencyCode = HttpUtil.getHttpServletRequest().getParameter("agencyCode");
			String logonId = HttpUtil.getHttpServletRequest().getParameter("logonId");
			String logonPwd = HttpUtil.getHttpServletRequest().getParameter("logonPwd");
			UserPermission permissionObject = new UserPermission();//this.getPermissionFacade().verifyPermission(agencyCode, logonId, logonPwd);
			permissionObject.setPermissibled(true);
			if(permissionObject!=null&&permissionObject.isPermissibled()){
				this.setUserSession(permissionObject.getUserSession());
				return LogonAction.LOGIN;
			}
//		}
//		catch (BIZException e) {
//			throw new WebPageException("logon fail:" + e.getMessage());
//		}
		return LogonAction.LOGOUT;
	}
	
	public String logout(){
		return LogonAction.LOGOUT;
	}

	public void setPermissionFacade(PermissionFacade permissionFacade) {
		this.permissionFacade = permissionFacade;
	}

	public PermissionFacade getPermissionFacade() {
		return permissionFacade;
	}
}
